import requests


# 千帆大模型平台
# https://console.bce.baidu.com/qianfan/overview
# api列表
# https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlks5zkzu
class BaiduTokenManager:
    _token = None

    @classmethod
    def get_token(cls, api_key, secret_key):
        if cls._token is None:
            response = requests.post("https://aip.baidubce.com/oauth/2.0/token", data={
                "grant_type": "client_credentials",
                "client_id": api_key,
                "client_secret": secret_key
            })
            response_data = response.json()
            cls._token = response_data["access_token"]
        return cls._token
